home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-05-09 | 7.2 KB | 181 lines | [TEXT/PJMM] |
- { *** DEMO FOR the IngisWDEF WDEF building package *** }
-
- {© 1994-1995 by Ingemar Ragnemalm}
- {You may use it freely as long as credits are given in the final program.}
-
-
- {This demo creates a window, where the number of corners is determined from the variant code.}
- {Try changing the variant code in the WIND resource in ResEdit. The window also has a bizarre drag}
- {blob in the upper left corner.}
-
- {This unit holds all custom code}
-
- unit CustomStubs;
-
- interface
- uses
- {$IFC UNDEFINED THINK_PASCAL}
- Types, QuickDraw, ToolUtils, Windows,
- {$ENDC}
- IngisWDEFUtils;
-
- {Lots of routines, right? Don't worry; you can skip several of them if you don't plan on supporting zoom box,}
- {close box or grow regions, and you can call some default routines in IngisWDEFUtils.}
-
- procedure GetGrowRgn (varCode: integer; macWindow: WindowPeek; var growRgn: RgnHandle);
- procedure GetCloseBox (varCode: integer; dragBar: RgnHandle; var closeBox: Rect);
- procedure GetZoomBox (varCode: integer; dragBar: RgnHandle; var zoomBox: Rect);
- procedure DrawCloseBox (varCode: integer; macWindow: WindowPeek; closeBox: Rect; colorFlag: Boolean);
- procedure DrawZoomBox (varCode: integer; macWindow: WindowPeek; zoomBox: Rect; colorFlag: Boolean);
- procedure DrawHitCloseBox (varCode: integer; macWindow: WindowPeek; closeBox: Rect; colorFlag: Boolean);
- procedure DrawHitZoomBox (varCode: integer; macWindow: WindowPeek; zoomBox: Rect; colorFlag: Boolean);
- procedure DrawDragBar (varCode: integer; macWindow: WindowPeek; dragBar: RgnHandle; colorFlag: Boolean);
- procedure BuildCustomRegions (varCode: integer; theRect: Rect; contRgn, dragRgn: RgnHandle);
- procedure DrawScrollFrame (varCode: integer; macWindow: WindowPeek; theRect: Rect);
- procedure DrawTheGrowIcon (varCode: integer; macWindow: WindowPeek; theRect: Rect; growRgn: RgnHandle; colorFlag: Boolean);
- procedure InitMyWindow (varCode: integer; macWindow: WindowPeek);
- procedure DisposeMyWindow (varCode: integer; macWindow: WindowPeek);
-
- {** Constants **}
- const
- kFrameWidth = 2; { Thickness of frame around window. 1 is normal.}
- kShadowLength = 2; { Size of drop shadow. 1 is normal.}
- kMinDepthForColor = 4; { Smallest pixel size for color. 8 (256 colors) is normal. }
- kMinWidth = 100; { Limits for the dragging rectangle? }
- kMinHeight = 100;
-
- type
- MyDataRecord = record
- theWindowState: WStateData;
- {Insert any globals you need here!}
- end;
- MyDataPtr = ^MyDataRecord;
- MyDataHandle = ^MyDataPtr;
-
- implementation
-
- {*****************************************************************************}
- { GetGrowRgn}
- { Return the region with the grow icon, if any.}
- { *****************************************************************************}
-
- procedure GetGrowRgn (varCode: integer; macWindow: WindowPeek; var growRgn: RgnHandle);
- begin
- end;
-
- {*****************************************************************************}
- { GetCloseBox}
- { Pass back a rectangle which encloses the close box of the window}
- { *****************************************************************************}
-
- procedure GetCloseBox (varCode: integer; dragBar: RgnHandle; var closeBox: Rect);
- begin
- end;
-
- procedure GetZoomBox (varCode: integer; dragBar: RgnHandle; var zoomBox: Rect);
- begin
- end;
-
- {*****************************************************************************}
- { Draw close box and zoom box, in normal and hit state }
- { Draw the close box in "hit" state. This can be as simple as an InvertRect. }
- { *****************************************************************************}
-
- procedure DrawCloseBox (varCode: integer; macWindow: WindowPeek; closeBox: Rect; colorFlag: Boolean);
- begin
- end; {}
- procedure DrawZoomBox (varCode: integer; macWindow: WindowPeek; zoomBox: Rect; colorFlag: Boolean);
- begin
- end; {}
- procedure DrawHitCloseBox (varCode: integer; macWindow: WindowPeek; closeBox: Rect; colorFlag: Boolean);
- begin
- end; {}
- procedure DrawHitZoomBox (varCode: integer; macWindow: WindowPeek; zoomBox: Rect; colorFlag: Boolean);
- begin
- end; {}
-
- {*****************************************************************************}
- { DrawDragBar, BW and Color version}
- { Draw the drag bar (not close box/zoom box)}
- { *****************************************************************************}
-
- procedure DrawDragBar (varCode: integer; macWindow: WindowPeek; dragBar: RgnHandle; colorFlag: Boolean);
- begin
- PaintRgn(dragBar);
- end; {DrawDragBar}
-
- {*****************************************************************************}
- { BuildCustomRegions}
- { Build the contents region and the drag bar region. The ONLY mandatory procedure!}
- { *****************************************************************************}
-
- procedure BuildCustomRegions (varCode: integer; theRect: Rect; contRgn, dragRgn: RgnHandle);
- var
- center, radius: Point;
- i: integer;
- step: Real;
- tmpRect: Rect;
- begin
- OpenRgn;
- if varCode = 0 then {0: No corners, isn't that an oval?}
- FrameOval(theRect)
- else if varCode = 2 then {2: Well, let's make a rounded-corner one}
- begin
- FrameRoundRect(theRect, 30, 30);
- end
- else {varCode = number of corners!}
- begin
- center.h := (theRect.right + theRect.left) div 2;
- center.v := (theRect.top + theRect.bottom) div 2;
- radius.h := (theRect.right - theRect.left) div 2;
- radius.v := (theRect.bottom - theRect.top) div 2;
- step := 2 * 3.1416 / varCode;
- MoveTo(center.h + radius.h, center.v);
- for i := 1 to varCode do
- begin
- {Jag tänkte mig att traska runt cirkeln och bygga en månghörning!}
- LineTo(center.h + trunc(radius.h * cos(i * step)), center.v + trunc(radius.v * sin(i * step)));
- end;
- LineTo(center.h + radius.h, center.v);
- end;
- CloseRgn(contRgn);
-
- SetRect(tmprect, theRect.left - 10, theRect.top - 10, theRect.left, theRect.top);
- OpenRgn;
- FrameOval(tmpRect); {Äsch, det gick inget bra!}
- CloseRgn(dragRgn);
- end; {BuildCustomRegions}
-
- {*****************************************************************************}
- { DrawScrollFrame}
- { Draw the scroll frame, if any (used both when resizing and when drawing the grow icon) }
- { *****************************************************************************}
-
- procedure DrawScrollFrame (varCode: integer; macWindow: WindowPeek; theRect: Rect);
- begin
- end; {DrawScrollFrame}
-
- {*****************************************************************************}
- { DrawTheGrowIcon, BW and Color version}
- { Draw the grow icon, if any }
- { *****************************************************************************}
-
- procedure DrawTheGrowIcon (varCode: integer; macWindow: WindowPeek; theRect: Rect; growRgn: RgnHandle; colorFlag: Boolean);
- begin
- end; {DrawTheGrowIcon}
-
- {*****************************************************************************}
- { InitMyWindow and DisposeMyWindow }
- { Can often be empty. Set the spareFlag in InitMyWindow if the variant should have a zoom box. }
- { InitMyWindow may initialize any globals in MyDataHandle(macWindow^.dataHandle). }
- { DisposeMyWindow must restore/dispose fields in MyDataHandle(macWindow^.dataHandle) as needed. }
- { *****************************************************************************}
-
- procedure InitMyWindow (varCode: integer; macWindow: WindowPeek);
- begin
- end; {}
- procedure DisposeMyWindow (varCode: integer; macWindow: WindowPeek);
- begin
- end; {}
-
- end.